<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<title>新闻发布系统管理后台</title>
<link href="news/css/admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="news/js/jquery-1.12.4.min.js"></script>
<!-- <script src="jquery.min.js"></script> -->
<script type="text/javascript">
	$(function(){
		$("#ntitle").blur(function(){
			var ntitle=$("#ntitle").val();
			if(ntitle==""){
				$("#prompt").html("标题不能为空");
				return;
			}
			
			$.post("CheckNtitleServlet",{ntitle:ntitle},function(data){
				if(data=="false"){
					$("#prompt").html("标题重复!");
					
				}else{
					$("#prompt").html("");
				}
			
			},"text")
		
		}) 
		
		
		/* $("#submit").click(function(){
			var ntitle=$("#ntitle").val();
			if(ntitle==""){
			$("#prompt").html("主题不能为空!");
				return false;
			}
			var isOk=true;
			$.ajax({
				url:"CheckNtitleServlet",
				type:"post",
				data:{ntitle:ntitle},
				dataType:"json",
				 async: false,
				 success:function(data){
				 	if(!data){
				 	isOk=false;
				 	}
				 }
			})
			if(!isOk){
			return false;
			}
		}) */
	})

</script>
</head>
<body>
	<jsp:include page="/AdminHeaderServlet"></jsp:include>
	<div id="main">
		<jsp:include page="/AdminLeftServlet"></jsp:include>

		<div id="opt_area">
			<h1 id="opt_type">添加新闻：</h1>
			<form action="DoAddNewsServlet" enctype="multipart/form-data"
				method="post">
				<p>
					<label> 主题 </label>
					 <select name="ntid" id="ntid">
						<c:forEach items="${listTopic}" var="t" >
							<option value='${t.tid}' >${t.tname}</option>
						</c:forEach>
					</select>
				</p>
				<p>
					<label> 标题 </label> <input name="ntitle" id="ntitle" type="text"
						class="opt_input" />
						<span id="prompt" style="color:red" ></span>
				</p>
				<p>
					<label> 作者 </label> <input name="nauthor" id=name=
						"nauthor" type="text" class="opt_input" />
				</p>
				<p>
					<label> 摘要 </label>
					<textarea name="nsummary" id="nsummary" cols="40" rows="3"></textarea>
				</p>
				<p>
					<label> 内容 </label>
					<textarea name="ncontent" id="ncontent" cols="70" rows="10"></textarea>
				</p>

				<p>
					<label> 上传图片 </label> <input type="file" name="nfile" id="file" onchange="bindAvatar2();" />
					<img src="news/images/index.gif" id="pic" alt="暂无图片" style="height:100px;width:130px" >
				</p>
				<script type="text/javascript">
						 var x=new FileReader;
					document.getElementById("file").onchange=function(){
					 	 x.readAsDataURL(this.files[0]);
					 }
					x.onloadend=function(){
						  document.getElementById("pic").src=this.result;
					 }
				</script>
				<input name="action" type="hidden" value="addnews" /> <input
					type="submit" id="sub" value="提交" class="opt_sub" /> <input type="reset"
					value="重置" class="opt_sub" />
			</form>
		</div>
	</div>
	<jsp:include page="/AdminFooterServlet"></jsp:include>
</body>
</html>
